﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using Entities;
using BUS;
using Utility;

public partial class Administrator_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_thongke();
            if (Session["username_admin"] != null)
            {
                load_data();
            }
        }
    }
    protected void bt_login_Click(object sender, EventArgs e)
    {
        Criteria cri = new Criteria();
        cri.add(Condition.AND, Tbl_NhanVien_Columns.TaiKhoan.ToString(), Condition.LIKE, txt_username.Text);
        int total = 0;
        Tbl_NhanVien_Collection nvCollection = Tbl_NhanVien_BUS.Get(cri.Criter, 0, 0, Tbl_NhanVien_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        if (nvCollection.Count > 0)
        {
            if (nvCollection[0].MatKhau == txt_pwd.Text)
            {
                Session["username_admin"] = txt_username.Text;
                txt_username.Text = "";
                txt_pwd.Text = "";
                lit_error.Text = "";
                Response.Redirect("~/Administrator/Default.aspx");
            }
            else
            {
                lit_error.Text = "Sai mật khẩu";
            }
        }
        else
        {
            lit_error.Text = "Tài khoản không tồn tại";
        }
    }

    protected void load_thongke()
    {
        Tbl_NhanVien_Collection dnCollection = Tbl_NhanVien_BUS.GetAll();
        Literal1.Text = dnCollection.Count.ToString();
        Tbl_DoanhNghiep_Entities dn = Tbl_DoanhNghiep_BUS.GetLast();
        Literal2.Text = dn.TenDN;
        Tbl_SanPham_Collection spCollection = Tbl_SanPham_BUS.GetAll();
        Literal3.Text = spCollection.Count.ToString();
        int open = Tbl_SanPham_BUS.GetByTinhTrang("Open");
        Literal4.Text = open.ToString();
        int close = Tbl_SanPham_BUS.GetByTinhTrang("Close");
        Literal5.Text = close.ToString();
        int chayhang = Tbl_SanPham_BUS.GetByTinhTrang("Cháy Hàng");
        Literal6.Text = chayhang.ToString();
        int hethan = Tbl_SanPham_BUS.GetByTinhTrang("Hết Hạn");
        Literal7.Text = hethan.ToString();
    }


    protected void load_data()
    {
        Tbl_NhanVien_Entities nv = Tbl_NhanVien_BUS.GetByUsername(Session["username_admin"].ToString());
        lit_tendn.Text = nv.TaiKhoan;
        
    }
}
